function display_result_progress(cv, DECODING_RESULTS, display_progress)
 % display current mean and stdev when a single bootstrap is left out for different result types
 % to give an idea whether the algorithm has converged to a stable decoding accuracy
 % (these values could be used for stopping criteria, rather than running a fixed number of bootstrap runs)

%==========================================================================

%     This code is part of the Neural Decoding Toolbox.
%     Copyright (C) 2011 by Ethan Meyers (emeyers@mit.edu)
% 
%     This program is free software: you can redistribute it and/or modify
%     it under the terms of the GNU General Public License as published by
%     the Free Software Foundation, either version 3 of the License, or
%     (at your option) any later version.
% 
%     This program is distributed in the hope that it will be useful,
%     but WITHOUT ANY WARRANTY; without even the implied warranty of
%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
%     GNU General Public License for more details.
% 
%     You should have received a copy of the GNU General Public License
%     along with this program.  If not, see <http://www.gnu.org/licenses/>.
    
%==========================================================================  
 
 
 
    iBootstrap = size(DECODING_RESULTS.ZERO_ONE_LOSS_RESULTS.decoding_results, 3);


     curr_bootstrap_progress_results = cell(5, 1);


     num_training_times = size(DECODING_RESULTS.ZERO_ONE_LOSS_RESULTS.decoding_results, 1);
     num_test_times = size(DECODING_RESULTS.ZERO_ONE_LOSS_RESULTS.decoding_results, 2);


     % default behavior if there is only 1 training point and display_progress.training_time_to_display_results == -1, is to just use this one training time for the results
     if (display_progress.training_time_to_display_results == -1)  && (num_training_times== 1)
         display_progress.training_time_to_display_results = 1;
     end


     % display_progress.training_time_to_display_results should be set if the num_training_times ~= num_test_times
     if (display_progress.training_time_to_display_results == -1) && (num_training_times~= num_test_times)

         warning(['If the number of training times does not equal the number of test times, and one wants to display the bootstrap progress, ' ...
                    'then display_progress.training_time_to_display_results should be set.  We are going to use the default value of display_progress.training_time_to_display_results = 1, ' ...
                    'to display the results here.'])

         display_progress.training_time_to_display_results = 1;

     end

     
     % more error checking, make sure not asking to display any results that were not calculated.
     if (display_progress.normalized_rank == 1) && ~isfield(DECODING_RESULTS, 'NORMALIZED_RANK_RESULTS')
        warning('Can not display_normalized rank results (i.e., progress.normalized_rank == 1) when they are not being calcluated/saved, Skipping displaying progress on these results')
        display_progress.normalized_rank = 0;
     end
     
     if (display_progress.decision_values == 1) && ~isfield(DECODING_RESULTS, 'DECISION_VALUES')
        warning('Can not display_decision (i.e., progress.decision_values == 1) when they are not being calculated/saved, Skipping displaying progress on these results')
        display_progress.decision_values = 0;
     end
     
     if (display_progress.separate_CV_ROC_results == 1) && ~isfield(DECODING_RESULTS.ROC_AUC_RESULTS, 'separate_CV_ROC_results')
        warning('Can not display separate CV ROC results (i.e., progress.separate_CV_ROC_results == 1) when they are not being calculated/saved, Skipping displaying progress on these results')
        display_progress.separate_CV_ROC_results = 0;
     end
     
     if (display_progress.combined_CV_ROC_results == 1) && ~isfield(DECODING_RESULTS.ROC_AUC_RESULTS, 'combined_CV_ROC_results')
        warning('Can not display combined CV ROC results (i.e., progress.separate_CV_ROC_results == 1) when they are not being calculated/saved, Skipping displaying progress on these results')
        display_progress.combined_CV_ROC_results = 0;
     end 


     
     
    % Create matrix curr_bootstrap_progress_results
    

    % if a particular training time that has been specified to display the results
    if display_progress.training_time_to_display_results > 0


        if display_progress.zero_one_loss, curr_bootstrap_progress_results{1} = squeeze(mean(DECODING_RESULTS.ZERO_ONE_LOSS_RESULTS.decoding_results(display_progress.training_time_to_display_results, :, :, :), 4));  end
        if display_progress.normalized_rank, curr_bootstrap_progress_results{2} = squeeze(mean(DECODING_RESULTS.NORMALIZED_RANK_RESULTS.decoding_results(display_progress.training_time_to_display_results, :, :, :), 4)); end
        if display_progress.decision_values, curr_bootstrap_progress_results{3} = squeeze(mean(DECODING_RESULTS.DECISION_VALUES.decoding_results(display_progress.training_time_to_display_results, :, :, :), 4)); end

        if display_progress.separate_CV_ROC_results, curr_bootstrap_progress_results{4} = squeeze(mean(mean(DECODING_RESULTS.ROC_AUC_RESULTS.separate_CV_ROC_results.decoding_results(display_progress.training_time_to_display_results, :, :, :, :), 5), 4));  end
        if display_progress.combined_CV_ROC_results, curr_bootstrap_progress_results{5} = squeeze(mean(DECODING_RESULTS.ROC_AUC_RESULTS.combined_CV_ROC_results.decoding_results(display_progress.training_time_to_display_results, :, :, :), 4));  end


        if iBootstrap == 1
            for i = 1:5
                curr_bootstrap_progress_results{i} = curr_bootstrap_progress_results{i}';
            end
        end


    else  % otherwise, do the default behavior of displaying test results only at the same training times  (num_training_times == num_test_times is true here)

        for iDisplayResultTrainingTime = 1:num_training_times 

            if display_progress.zero_one_loss, curr_bootstrap_progress_results{1}(iDisplayResultTrainingTime, :) = squeeze(mean(DECODING_RESULTS.ZERO_ONE_LOSS_RESULTS.decoding_results(iDisplayResultTrainingTime, iDisplayResultTrainingTime, :, :), 4));  end
            if display_progress.normalized_rank, curr_bootstrap_progress_results{2}(iDisplayResultTrainingTime, :) = squeeze(mean(DECODING_RESULTS.NORMALIZED_RANK_RESULTS.decoding_results(iDisplayResultTrainingTime, iDisplayResultTrainingTime, :, :), 4)); end
            if display_progress.decision_values, curr_bootstrap_progress_results{3}(iDisplayResultTrainingTime, :) = squeeze(mean(DECODING_RESULTS.DECISION_VALUES.decoding_results(iDisplayResultTrainingTime, iDisplayResultTrainingTime, :, :), 4)); end

            if display_progress.separate_CV_ROC_results, curr_bootstrap_progress_results{4}(iDisplayResultTrainingTime, :) = squeeze(mean(mean(DECODING_RESULTS.ROC_AUC_RESULTS.separate_CV_ROC_results.decoding_results(iDisplayResultTrainingTime, iDisplayResultTrainingTime, :, :, :), 5), 4)); end
            if display_progress.combined_CV_ROC_results, curr_bootstrap_progress_results{5}(iDisplayResultTrainingTime, :) = squeeze(mean(DECODING_RESULTS.ROC_AUC_RESULTS.combined_CV_ROC_results.decoding_results(iDisplayResultTrainingTime, iDisplayResultTrainingTime, :, :), 4)); end

        end

    end




   if iBootstrap == 1
       curr_total_mean = curr_bootstrap_progress_results;   % can't show cofficients of variation if only 1 bootstrap has been run (so skip the following part)
   else

        % calculate the results if one bootstrap run is left out (to get a sense of whether enough bootstraps have been run so that the mean result has converged)
        for iResultType = 1:5
            if ~isempty(curr_bootstrap_progress_results{iResultType})
                curr_total_mean{iResultType} = mean(curr_bootstrap_progress_results{iResultType}, 2);
                curr_one_bootstrap_left_out_mean{iResultType} = ((repmat(curr_total_mean{iResultType}, [1 iBootstrap]) - (curr_bootstrap_progress_results{iResultType}./iBootstrap)) .* (iBootstrap./(iBootstrap -1)))';   % means over bootstraps with the ith bootstrap result left out
                curr_stdev_one_bootstrap_left_out{iResultType} = std(curr_one_bootstrap_left_out_mean{iResultType});  % stdev over results when one bootstrap sample is left out
            end    
        end

   end


   % compile the results to display
   current_bootstrap_results = [];
   for iResultType = 1:5
       if ~isempty(curr_bootstrap_progress_results{iResultType})
            current_bootstrap_results = [current_bootstrap_results; curr_total_mean{iResultType}'];
            if exist('curr_stdev_one_bootstrap_left_out')
                current_bootstrap_results = [current_bootstrap_results; curr_stdev_one_bootstrap_left_out{iResultType}];
                %current_bootstrap_results = [current_bootstrap_results; curr_stdev_one_bootstrap_left_out{iResultType}./curr_total_mean{iResultType}'];  % add mean results and coefficient of variation for leaving one bootstrap sample out
            end

            current_bootstrap_results = [current_bootstrap_results; NaN .* ones(size(curr_total_mean{iResultType}'))];

       end                      
   end


   current_bootstrap_results








